package cn.zhz.privacy.sensitive.handler;

import cn.hutool.core.util.StrUtil;
import cn.zhz.privacy.sensitive.SensitiveType;
import cn.zhz.privacy.sensitive.SensitiveTypeHandler;

/**
 * 身份证号脱敏类型
 * 前3位，后4位
 * 130722199102323232 脱敏后: 130*************3232
 * @author ;
 */
public class IDCardSensitiveHandler implements SensitiveTypeHandler {
    @Override
    public SensitiveType getSensitiveType() {
        return SensitiveType.ID_CARD;
    }

    @Override
    public String handle(Object src) {
        if(src==null){
            return null;
        }
        String idCard = src.toString();
        int len=idCard.length();
        if(len<=8){
            return idCard;
        }
        return StrUtil.subPre(idCard, 3)
                .concat("*************")
                .concat(StrUtil.subSufByLength(idCard,4));

    }
}
